package com.tom.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author xuejun zeng
 */
@Configuration
public class SchedulerConfiguration implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        int size = Runtime.getRuntime().availableProcessors() * 2;
        taskRegistrar.setScheduler(new ScheduledThreadPoolExecutor(size, new CustomizableThreadFactory("scheduler-")));
    }
}
